/**
 * Author: Dmitry Ustimov
 * Date: 5/31/13
 * Time: 8:14 PM
 */

package com.gmail.dmitryustimov.ms.java7.mediator.mod.work.demo.col10event10;

import com.gmail.dmitryustimov.ms.java7.patternslib.mediator.Colleague;
import com.gmail.dmitryustimov.ms.java7.patternslib.mediator.EventPublisher;
import com.gmail.dmitryustimov.ms.java7.patternslib.mediator.SubscriberAction;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class Mediator implements Colleague {

    private String name;
    private List<Colleague> colleagueList = new ArrayList<>();
    private BigDecimal sum = BigDecimal.valueOf(0);

    private EventPublisher<Event1> event1Publisher = new EventPublisher<>();
    private EventPublisher<Event2> event2Publisher = new EventPublisher<>();
    private EventPublisher<Event3> event3Publisher = new EventPublisher<>();
    private EventPublisher<Event4> event4Publisher = new EventPublisher<>();
    private EventPublisher<Event5> event5Publisher = new EventPublisher<>();
    private EventPublisher<Event6> event6Publisher = new EventPublisher<>();
    private EventPublisher<Event7> event7Publisher = new EventPublisher<>();
    private EventPublisher<Event8> event8Publisher = new EventPublisher<>();
    private EventPublisher<Event9> event9Publisher = new EventPublisher<>();
    private EventPublisher<Event10> event10Publisher = new EventPublisher<>();

    public Mediator(String name) {
        this.name = name;
    }

    public void addColleague(AbstractColleague colleague) {
        colleagueList.add(colleague);
        colleague.getEvent1Publisher().subscribe(this.new Event1Action());
        colleague.getEvent2Publisher().subscribe(this.new Event2Action());
        colleague.getEvent3Publisher().subscribe(this.new Event3Action());
        colleague.getEvent4Publisher().subscribe(this.new Event4Action());
        colleague.getEvent5Publisher().subscribe(this.new Event5Action());
        colleague.getEvent6Publisher().subscribe(this.new Event6Action());
        colleague.getEvent7Publisher().subscribe(this.new Event7Action());
        colleague.getEvent8Publisher().subscribe(this.new Event8Action());
        colleague.getEvent9Publisher().subscribe(this.new Event9Action());
        colleague.getEvent10Publisher().subscribe(this.new Event10Action());
    }

    private class Event1Action extends SubscriberAction<Event1> {
        public Event1Action() {
            super(Mediator.this);
        }

        @Override
        public void process(Event1 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
            event1Publisher.publish(event, originator);
        }
    }

    private class Event2Action extends SubscriberAction<Event2> {
        public Event2Action() {
            super(Mediator.this);
        }

        @Override
        public void process(Event2 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
            event2Publisher.publish(event, originator);
        }
    }

    private class Event3Action extends SubscriberAction<Event3> {
        public Event3Action() {
            super(Mediator.this);
        }

        @Override
        public void process(Event3 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
            event3Publisher.publish(event, originator);
        }
    }

    private class Event4Action extends SubscriberAction<Event4> {
        public Event4Action() {
            super(Mediator.this);
        }

        @Override
        public void process(Event4 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
            event4Publisher.publish(event, originator);
        }
    }

    private class Event5Action extends SubscriberAction<Event5> {
        public Event5Action() {
            super(Mediator.this);
        }

        @Override
        public void process(Event5 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
            event5Publisher.publish(event, originator);
        }
    }

    private class Event6Action extends SubscriberAction<Event6> {
        public Event6Action() {
            super(Mediator.this);
        }

        @Override
        public void process(Event6 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
            event6Publisher.publish(event, originator);
        }
    }

    private class Event7Action extends SubscriberAction<Event7> {
        public Event7Action() {
            super(Mediator.this);
        }

        @Override
        public void process(Event7 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
            event7Publisher.publish(event, originator);
        }
    }

    private class Event8Action extends SubscriberAction<Event8> {
        public Event8Action() {
            super(Mediator.this);
        }

        @Override
        public void process(Event8 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
            event8Publisher.publish(event, originator);
        }
    }

    private class Event9Action extends SubscriberAction<Event9> {
        public Event9Action() {
            super(Mediator.this);
        }

        @Override
        public void process(Event9 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
            event9Publisher.publish(event, originator);
        }
    }

    private class Event10Action extends SubscriberAction<Event10> {
        public Event10Action() {
            super(Mediator.this);
        }

        @Override
        public void process(Event10 event, Colleague originator) {
            sum.add(BigDecimal.valueOf(1));
            event10Publisher.publish(event, originator);
        }
    }

    public EventPublisher<Event1> getEvent1Publisher() {
        return event1Publisher;
    }

    public void setEvent1Publisher(EventPublisher<Event1> event1Publisher) {
        this.event1Publisher = event1Publisher;
    }

    public EventPublisher<Event2> getEvent2Publisher() {
        return event2Publisher;
    }

    public void setEvent2Publisher(EventPublisher<Event2> event2Publisher) {
        this.event2Publisher = event2Publisher;
    }

    public EventPublisher<Event3> getEvent3Publisher() {
        return event3Publisher;
    }

    public void setEvent3Publisher(EventPublisher<Event3> event3Publisher) {
        this.event3Publisher = event3Publisher;
    }

    public EventPublisher<Event4> getEvent4Publisher() {
        return event4Publisher;
    }

    public void setEvent4Publisher(EventPublisher<Event4> event4Publisher) {
        this.event4Publisher = event4Publisher;
    }

    public EventPublisher<Event5> getEvent5Publisher() {
        return event5Publisher;
    }

    public void setEvent5Publisher(EventPublisher<Event5> event5Publisher) {
        this.event5Publisher = event5Publisher;
    }

    public EventPublisher<Event6> getEvent6Publisher() {
        return event6Publisher;
    }

    public void setEvent6Publisher(EventPublisher<Event6> event6Publisher) {
        this.event6Publisher = event6Publisher;
    }

    public EventPublisher<Event7> getEvent7Publisher() {
        return event7Publisher;
    }

    public void setEvent7Publisher(EventPublisher<Event7> event7Publisher) {
        this.event7Publisher = event7Publisher;
    }

    public EventPublisher<Event8> getEvent8Publisher() {
        return event8Publisher;
    }

    public void setEvent8Publisher(EventPublisher<Event8> event8Publisher) {
        this.event8Publisher = event8Publisher;
    }

    public EventPublisher<Event9> getEvent9Publisher() {
        return event9Publisher;
    }

    public void setEvent9Publisher(EventPublisher<Event9> event9Publisher) {
        this.event9Publisher = event9Publisher;
    }

    public EventPublisher<Event10> getEvent10Publisher() {
        return event10Publisher;
    }

    public void setEvent10Publisher(EventPublisher<Event10> event10Publisher) {
        this.event10Publisher = event10Publisher;
    }
}
